<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<title>Item Searching</title>
<script type="text/javascript" src="/p2ptrade/js/json.js"></script>
<script type="text/javascript" src="/p2ptrade/js/ajax.js"></script>
<script type="text/javascript" src="/p2ptrade/js/prototype.js"></script>
<script>
var OldItemList = new Object();
var query = "";
var cell_object;
var default_html;
var action;

function SearchItem(query_term)
{
	cell_object = document.getElementById("ItemList");
	default_html = "<tr>\n<td class=\"header\" align=\"center\">Item</td>\n<td class=\"header\" align=\"center\">Owner</td>\n<td class=\"header\" align=\"center\">Memo</td>\n</tr>";
	var req = createAjaxRequest2(function(result){
          if (result.success){
          	if(result.result)
          	{
          		var ItemList = result.result;
          		if((action == "start") || (OldItemList.length!=ItemList.length))
          		{   			
  					var field_html = default_html;
  					for (var i=0; i<ItemList.length;i++){
					      field_html+="<tr>\n";
					      field_html+="<td>"+ItemList[i].name+"</td>\n";
					      field_html+="<td>"+ItemList[i].ownerId+"</td>\n";
					      field_html+="<td>"+ItemList[i].memo+"</td>\n";
					      field_html+="</tr>\n";
   					}
   					cell_object.innerHTML=field_html;
   					OldItemList = ItemList;
   				}
          }
          setTimeout("SearchItem(query)",5000);
        }});
    if(query_term!=query)
    {
    	cell_object.innerHTML=default_html;
    	action = "start";
    }
    else
    	action = "refresh";
    
    query = query_term;
   	var url = "/p2ptrade/item/itemSearching.do?query="+query+"&action="+action;
  	req.open("GET", url , true);
  	req.send(null);
}

/*function CheckResult()
{
	var req = createAjaxRequest2(function(result){
          if (result.success){
				alert(result.result.myItems[1].name);
          }
        });
   	var url = "/p2ptrade/item/searchResult.do";
   	
  	req.open("GET", url , true);
  	req.send(null);
}*/
//CheckResult();
//window.setInterval( "CheckResult()",10000 );

</script>
<link href="../css/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<form name="search_item" method="post">
	<div align="center">
	
	<jsp:include page="/top.tpl" />
	<br>
	<div>
	  <p>
	    <input name="query_term" type="text" class="text_font" size="20">　
	    <input name="search_button" type="button" class="text_font" onClick="SearchItem(document.forms[0].query_term.value);" value="search">
	  </p>
	  <p>&nbsp; </p>
	</div>	
	<br>
	<div>
		<table width="500" border="0" cellpadding="0" cellspacing="0" id="ItemList">
			<tr>
				<td class="header"><div align="center">Item</div></td>
				<td class="header"><div align="center">Owner</div></td>
				<td class="header"><div align="center">Memo</div></td>
			</tr>
	  </table>
	</div>
	
	</div>
	
</form>


</body>
</html>